<?php
/*
 * Created by PhpStorm.
 * User: iwm
 * Date: 2017/1/23
 * Time: 11:36
 */

namespace app\home\controller;

use app\home\model\page\circle\AddLabel;
use app\home\model\page\circle\AddLogo;
use app\home\model\page\circle\ApproveCircle as ApproveCircleModel;
use app\home\model\page\circle\CircleCategoryPage;
use app\home\model\page\circle\ConsumerRankPage;
use app\home\model\page\circle\GetCircleList as GetCircleListModel;

use app\home\model\page\circle\NoteListPage;
use app\home\model\page\circle\UpRankPage;
use think\Request;

use think\Controller;

class Circle extends Controller
{

    private $approveCircleModel;
    private $getCircleListModel;

    protected $param;

    public function __construct()
    {
        parent::__construct();

        $this->param = Request::instance()->param();

        $this->approveCircleModel = new ApproveCircleModel();
        $this->getCircleListModel = new GetCircleListModel();
    }

    public function getUnReviewedCircle()
    {
        $data = $this->getCircleListModel->excute($this->param);
        //return  JSON($data);
        $str = $data['data']['html_page'];
        //$baseUrl = Request::instance()->baseUrl();
        $urlParam = Request::instance()->param();
        unset($urlParam['page']);
        $preg = "/\?page=[1-9]/";
        if (preg_match_all($preg, $str, $match)) {
            $match = array_unique($match[0]);
            $tmp = '';
            foreach ($urlParam as $key => $value) {
                $tmp = $tmp . '&' . $key . "=" . $value;
            }
            foreach ($match as $value) {
                $str = str_replace($value, $value . $tmp, $str);
            }
            $data['data']['html_page'] = $str;
        }

        $this->assign('data', $data['data']);
        return $this->fetch('home/pages/circle/unreviewedcircle');
    }

    /**
     * 审核圈子
     *
     * @return array
     */
    public function approveCircle()
    {
        $ret = $this->approveCircleModel->excute($this->param);
        return json($ret);
    }

    /**
     * 审核圈子
     *
     * @return array
     */
    public function getCircleList()
    {
        $ret = $this->getCircleListModel->excute($this->param);
        return json($ret);
    }

    public function noteListPage()
    {
        $obj = New NoteListPage();
        $ret = $obj->excute($this->param);
        //return JSON(($ret));
        $this->assign('data', $ret['data']);
        return $this->fetch('home/pages/circle/notelist');
    }

    public function upRankPage()
    {
        $obj = new UpRankPage();
        $ret = $obj->excute($this->param);
        //return JSON($ret);
        $this->assign('data', $ret['data']);
        return $this->fetch('home/pages/circle/uprank');
    }

    public function consumerRankPage()
    {
        $obj = new ConsumerRankPage();
        $ret = $obj->excute($this->param);
        //return JSON($ret);
        $this->assign('data', $ret['data']);
        return $this->fetch('home/pages/circle/consumerrank');
    }

    public function circleCategoryPage()
    {
        $obj = new CircleCategoryPage();
        $ret = $obj->excute($this->param);
        //return JSON($ret);
        $this->assign('data', $ret['data']);
        return $this->fetch('home/pages/circle/category');
    }

    public function addLabel()
    {
        $obj = new AddLabel();
        $ret = $obj->excute($this->param);
        return JSON($ret);
    }

    public function addLogo()
    {
        $obj = new AddLogo();
        $ret = $obj->excute($this->param);
        return JSON($ret);
    }

}
